package com.yin.myproject.arithmetic;

import java.util.Arrays;

/**
 * @author Eason
 * @create 2018-04-20 14:14
 **/
public class StraightSelectionSorter {
    public static void main(String[] args) {
        int array[] = {94, 12, 34, 76, 26, 9, 0, 37, 55, 76, 37, 5, 68, 83, 90, 37, 12, 65, 76, 49};
        StraightSelectionSorter sorter = new StraightSelectionSorter();
        int[] sort = sorter.sort(array);
        System.out.println(Arrays.toString(sort));
    }

    private int[] sort(int[] array) {
        int temp;
        int length = array.length;
        for (int i = 0; i < length; i++) {
            int k = i;
            for (int j = i + 1; j < length; j++) {
                if (array[k] > array[j]) {
                    k = j;
                }
            }
            if (array[i] > array[k]) {
                temp = array[i];
                array[i] = array[k];
                array[k] = temp;
            }
        }
        return array;
    }
}
